insert
    overwrite
    table jms_dm.dm_cusc_entity_customer_network_province_kg_summary_month_dt
    partition
    (dt)
select customer_entity_code                                                          --客户实体code
     , customer_entity_name                                                          --客户实体name
     , customer_network_code                                                         --客户网点code
     , customer_network_name                                                         --客户网点name
     , customer_agent_code                                                           --客户代理区code
     , customer_agent_name                                                           --客户代理区name
     , customer_virt_code                                                            --客户虚拟代理区code
     , customer_virt_name                                                            --客户虚拟代理区name
     , customer_code                                                                 --客户code
     , customer_name                                                                 --客户name
     , receiver_province_id                                                          --签收省份id
     , receiver_province_name                                                        --签收省份name
     , kg_part                                                                       --重量段
     , kg_part_two                                                                   --重量段
     , weight_total                                                                  --总重量
     , waybill_num                                                                   --揽收量
     , sum(waybill_num) over (partition by dt,customer_code) as customer_waybill_num --客户揽收量
     , sum(if(customer_entity_code is not null, waybill_num, 0))
           over (partition by dt, customer_entity_code)      as entity_waybill_num   --客户实体揽收量
     , date_time                                                                     --月第一天
     , update_time
     , dt                                                                            --分区
from (
         select customer_entity_code                                                   --客户实体code
              , customer_entity_name                                                   --客户实体name
              , customer_network_code                                                  --客户网点code
              , customer_network_name                                                  --客户网点name
              , customer_agent_code                                                    --客户代理区code
              , customer_agent_name                                                    --客户代理区name
              , customer_virt_code                                                     --客户虚拟代理区code
              , customer_virt_name                                                     --客户虚拟代理区name
              , customer_code                                                          --客户code
              , customer_name                                                          --客户name
              , receiver_province_id                                                   --签收省份id
              , receiver_province_name                                                 --签收省份name
              , kg_part                                                                --重量段
              , kg_part_two                                                            --重量段
              , sum(weight_total)                                      as weight_total --总重量
              , sum(waybill_num)                                       as waybill_num  --揽收量
              , month_fst_date                                         as date_time    --月第一天
              , from_unixtime(unix_timestamp(), 'yyyy-MM-dd HH:mm:ss') as update_time
              , month_fst_date                                         as dt           --分区
         from jms_dm.dm_cusc_entity_customer_network_province_kg_summary_day_dt
         where dt <= '{{ execution_date | cst_ds }}'
           and dt >= trunc(add_months('{{ execution_date | cst_ds }}', -1), 'MM')
         group by customer_entity_code   --客户实体code
                , customer_entity_name   --客户实体name
                , customer_network_code  --客户网点code
                , customer_network_name  --客户网点name
                , customer_agent_code    --客户代理区code
                , customer_agent_name    --客户代理区name
                , customer_virt_code     --客户虚拟代理区code
                , customer_virt_name     --客户虚拟代理区name
                , customer_code          --客户code
                , customer_name          --客户name
                , receiver_province_id   --签收省份id
                , receiver_province_name --签收省份name
                , kg_part                --重量段
                , kg_part_two            --重量段
                , month_fst_date --月第一天
     ) a
distribute by pmod(hash(receiver_province_id),10)